package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JdbcDemo05 {
    public static void main(String[] args) {
        try (
              Connection connection = DbUtil.getConnection();
              ){
            Statement statement = connection.createStatement();
            String str = "SELECT t.name,t.salary,t.title,c.name,c.floor\n" +
                    "FROM teacher t \n" +
                    "JOIN class c ON t.id = c.teacher_id\n" +
                    "WHERE t.name = '王克晶'";
            ResultSet rs = statement.executeQuery(str);
            while (rs.next()){
                String tName = rs.getString("t.name");
                int tSalary = rs.getInt("t.salary");
                String tTitle = rs.getString("t.title");
                String cName = rs.getString("c.name");
                int cFloor = rs.getInt("c.floor");
                System.out.println(tName+" "+tSalary+" "+tTitle+" "+cName+" "+cFloor+" ");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
